@extends('layouts.default')
@section('content')
@include('modules.thanhmenu')
<?php
if(HomeController::checkInTime('kh')){
    
	$kehoach = new CanBoQLKeHoach();
	$nienkhoahockyhientai = new HomeController();
	$nienkhoahockyhientai = $nienkhoahockyhientai->shownienkhoahockyhientai();
	$motacongviec = $kehoach->lay_mo_ta_cong_viec();	

	$dsdetai = new CanBoQLDeTaiVaSVDK();
	$dsdetai = $dsdetai->show(Session::get('infor.id_nd')[0], 
									$nienkhoahockyhientai->nien_khoa,
									$nienkhoahockyhientai->hoc_ky);
	if(Session::has('ketqualuu'))
	{
     	if(Session::has('ketqualuu')==1)
          	echo "<script>alert('Lưu Thành Công')</script>";
          else
		{
          	echo "<script>alert('Lưu Thất Bại')</script>";
          }
     }
	if(Session::has('ketquathem'))
	{
     	if(Session::has('ketquathem')==1)
          	echo "<script>alert('Thêm Thành Công')</script>";
          else
		{
          	echo "<script>alert('Thêm Thất Bại')</script>";
          }
     }
	if(Session::has('ketquasua'))
	{
     	if(Session::has('ketquasua')==1)
          	echo "<script>alert('Sửa Thành Công')</script>";
          else
		{
          	echo "<script>alert('Sửa Thất Bại')</script>";
          }
     }
?>
<table cellpadding="10px" border="0">
	<tr>
		<td align="right">Chọn đề tài:</td>
		<form action='' method='get'>
		<td align='center'>	
			<select style='height: 30px;' name='tdetai'>
			<?php
			foreach ($dsdetai as $dsdetais) 
			{
			?>
				<option>
				<?php
					echo $dsdetais->ten_de_tai; 
                   	?>
				</option>
			<?php
			}
			?>
			</select>
		</td>
		<td>
			<input style="width: 100%; height: 30px; font-weight: bold;" name='xemkehoach' type='submit' value='Xem Kế Hoạch'>
		</td>
		</form>
	</tr>
</table>
<?php
if (isset($_GET['xemkehoach']))
{
	$tdetai = $_GET['tdetai'];
	$iddetai = $kehoach->getiddetai($tdetai)->id;
	$chitietdetai = $kehoach->lay_chi_tiet_de_tai($iddetai);
	
	$motakehoach = $kehoach->lay_ke_hoach_huong_dan($iddetai);
	
	$dskhhuongdan = $kehoach->lay_chi_tiet_ke_hoach_huong_dan($iddetai);
	$dsidkehoach = $kehoach->lay_id_ke_hoach($iddetai);
	foreach ($dsidkehoach as $dsidkehoachs)
	{
     	$idkehoach = $dsidkehoachs->id;
	} 
	?>
<table style="width: 100%" cellspacing="5" cellpadding="0" border="0">
	<tr>
		<td align='center' style="color: white; background-color: #336699; font-size: 14px; font-weight: bold; height: 30px; width: 20%">
			Tên Đề Tài
		</td>
		<td align='center' colspan='3'>
			<?php
			foreach ($chitietdetai as $chitietdetais)
			{
				echo $chitietdetais->ten_de_tai;	
			}   
			?>   
		</td>
		
	</tr>
	<tr>
		<td align='center' style="color: white; background-color: #336699; font-size: 14px; font-weight: bold; height: 30px;">
			Mô Tả Đề Tài
		</td>
		<td align='center' colspan='3'>
			<?php  
			foreach ($chitietdetai as $chitietdetais)
			{
				echo $chitietdetais->mo_ta_de_tai;	
			}   
			?>
		</td>
		
	</tr>
	<tr height='100%'>
		<td align='center' style="color: white; background-color: #336699; font-size: 14px; font-weight: bold; height: 30px;">
			Mô Tả Kế Hoạch 
		</td>
			<td align='left' colspan='3'>
			<textarea style="text-align: left; width: 99%; height: 100%;" name="txtMoTaKeHoach" form="frmLuu"><?php 
			foreach ($motakehoach as $motakehoachs)
			{
				echo $motakehoachs->mo_ta_ke_hoach;
			}
			?></textarea> 
		</td>
		
	</tr>
	<tr>
		<td colspan= "4" align='center' style="color: white; background-color: #336699; font-size: 14px; font-weight: bold; height: 30px;">
			Nội Dung Kế Hoạch: 
		</td>
	</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="5" >
	<tr>
		<td width="15%" align='center'>
			Tuần
		</td>
		<td width="30%" align='center'>
			Công việc
		</td>
		<td width="30%" align='center'>
			Ghi chú 
		</td>
		<td width="15%" align='center'>
			Thay đổi
		</td>
		
	</tr>
	<?php
	
	foreach ($dskhhuongdan as $dskhhuongdans) 
	{
		echo "<form action='".URL."cb/5/kh/suakehoach' method='post'>";
		echo "<tr>";
			echo "<td align = 'center'>";
				echo "<input style='width: 100%; height: 30px;' name='txtTuan' required value='".$dskhhuongdans->tuan."'>";
			echo "</td>";
			echo "<td align = 'center'>";
				echo "<select style='width: 100%; height: 35px;' name='txtMoTaCongViec' required>";
				foreach ($motacongviec as $motacongviecs) 
				{
					if ($motacongviecs->mo_ta_cong_viec == $dskhhuongdans->mo_ta_cong_viec)
					{
						echo "<option selected>";
							echo $dskhhuongdans->mo_ta_cong_viec;
						echo "</option>";
					}
					else 
					{
						echo "<option>";
							echo $motacongviecs->mo_ta_cong_viec;
						echo "</option>";
					}  
				}
				echo "</select>";
			echo "</td>";	
			echo "<td align = 'center'>";
				echo "<textarea style='height: 30px; width: 100%;'>".$dskhhuongdans->ghi_chu_cong_viec."</textarea>";
			echo "</td>";
			echo "<td align = 'center'>";
					echo "<input style='width: 60%; height: 30px; color: red; font-weight: bold;' type='submit' value='Sửa' name='sua'>";
					echo "<input style='display: none' 
						type='text' value='".$dskhhuongdans->id."'
						name='txtIDChiTietKeHoach'>";
			echo "</td>";
				
		echo "</tr>";	
		echo "</form>";
	}
	echo "<form name='frmThemKeHoach' id='frmThemKeHoach' method='post' action='";
	echo URL."cb/5/kh/themkehoach'>";
	echo "<input style='margin-left: 200px; display: none;' 
	type='number' value='".$idkehoach."' name='txtIDKeHoach'/>";
		echo "<tr>";
							
				echo "<td align = 'center'>
					<input style='width: 100%; height: 30px;' name='txtTuan' required>";
				echo "</td>";	
				echo "<td align = 'center'>";
					echo "<select style='width: 100%; height: 35px;' name='txtMoTaCongViec'>";
						foreach ($motacongviec as $motacongviecs) 
						{
							echo "<option>";
								echo $motacongviecs->mo_ta_cong_viec;
							echo "</option>";
						}
					echo "</select>";	
				echo "</td>"; 
				echo "<td align = 'center'><textarea style='width: 100%;' name='txtGhiChu'></textarea>";
				echo "</td>";
					echo "<td align = 'center'>
						<input style='width: 60%; height: 30px; color: green; font-weight: bold;' form='frmThemKeHoach' 
							type='submit' name='them' value='Thêm'>";
				echo "</td>";
				
		echo "</tr>";	
	echo "</form>";
	?>
	<tr>
		<td align="center" colspan="4">
			<form action="<?=URL?>cb/5/kh/luukehoach" id="frmLuu" name="frmLuu" method="post">
				<?php
				echo "<input style='margin-left: 200px; display: none;' 
					type='number' value='".$idkehoach."' 
					name='txtIDKeHoach'>";
				?>
				<input style = "width: 10%; height: 30px; font-weight: bold;" type="submit" value="Lưu" name="luu">
			</form>
		</td>
	</tr>
	</table>
<?php
}
}
 else {
   echo "<script>alert('Đã hết thời gian lập kế hoạch!');</script>";   
}
?>
@stop

